package com.geyb.model;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.geyb.domain.TypeConfig;
import com.geyb.util.GetSeriesByList;

/*
 * 
 * 0100..00100.
 */
public class Model2 implements IModel {
	private static final String regex1 = "^01000+";
	private static final String regex2 = "^0100100+";
	private static final String regex3 = "^01000+101";
	private static final String regex4 = "^0110110+";

	@Override
	public String getPredict(List<TypeConfig> tList) {
		String result = "";
		String series = GetSeriesByList.getSeries(tList);
		Pattern pattern1 = Pattern.compile(regex1);
		Pattern pattern2 = Pattern.compile(regex2);
		Pattern pattern3 = Pattern.compile(regex3);
		Pattern pattern4 = Pattern.compile(regex4);
		Matcher matcher1 = pattern1.matcher(series);
		Matcher matcher2 = pattern2.matcher(series);
		Matcher matcher3 = pattern3.matcher(series);
		Matcher matcher4 = pattern4.matcher(series);
		if ((matcher1.find() && !matcher3.find()) || matcher2.find()) {
			result = tList.get(0).getType();
		}else if(matcher3.find() || matcher4.find()){
			result = tList.get(1).getType();
		}
		return result;
	}
	
	public static String test(String series) {
		Pattern pattern1 = Pattern.compile(regex1);
		Pattern pattern2 = Pattern.compile(regex2);
		Pattern pattern3 = Pattern.compile(regex3);
		Pattern pattern4 = Pattern.compile(regex4);
		Matcher matcher1 = pattern1.matcher(series);
		Matcher matcher2 = pattern2.matcher(series);
		Matcher matcher3 = pattern3.matcher(series);
		Matcher matcher4 = pattern4.matcher(series);
		if ((matcher1.find() && !matcher3.find()) || matcher2.find()) {
			return "0";
		}else if(matcher3.find() || matcher4.find()){
			return "1";
		}
		return "";
	}
}
